<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{margin: 0;padding: 0;}
        ul,li{
            border: 1px solid #000;
        }
        ul{
            width: 120px;
            box-sizing: border-box;
            display: none;
            position: absolute;
        }
        li{
            height: 25px;
            padding-left: 10px;
            line-height: 25px;
            list-style: none;
        }
    </style>
</head>
<body>
    <ul>
        <li>新建</li>
        <li>剪切</li>
        <li>复制</li>
        <li>粘贴</li>
        <li>删除</li>
    </ul>
    <script>
        var oUl=document.querySelector("ul");
        var oLis=document.querySelectorAll("li");

        document.oncontextmenu=function(evt){
            var e=evt||window.event;
            oUl.style.left=e.pageX+("px");
            oUl.style.top=e.pageY+("px");
            oUl.style.display="block";
            return false;
        }

        document.onclick=function(){
            oUl.style.display="none";
        }

        oUl.onmouseover=function(evt){
            var e=evt||window.event;
            var ele=e.target||e.srcElement;
            if(ele.nodeName!="LI"){
                return;
            }
            for(var i=0;i<ele.parentNode.children.length;i++){
                ele.parentNode.children[i].style.backgroundColor="";
            }
            ele.style.backgroundColor="#c0c0c0";
        }
        oUl.onclick=function(evt){
            var e=evt||window.event;
            var ele=e.target||e.srcElement;
            if(ele.nodeName!="LI"){
                return;
            }
            console.log(ele.innerText);
            this.style.display="none";
        }
    </script>
</body>
</html>